package com.example.demo.thread;

/**
 *
 * @author czj
 * 无返回参数
 */
public class RunnableTest implements Runnable {

    private String name;

    public RunnableTest (String name){
        this.name = name;
    }

    @Override
    public void run() {
        Thread.currentThread().setName(name);
        System.out.println(Thread.currentThread().getName()+",sleep 3 seconds");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        for (int i = 0; i < 5; i++) {
            RunnableTest runnableTest = new RunnableTest(i + "");

            Thread thread = new Thread(runnableTest);
            thread.start();
            System.out.println(thread.getName());
        }
    }
}
